package src;

import java.util.LinkedList;


public class Dup {

	public static void main(String[] args) {
		
		int[] inputA = {1,1,1,2,3,4,4,5,6,7,8,8,1,2};
		LinkedList<Integer> outputBReverse = new LinkedList<Integer>();
		int[] outputB;
		int[] outputC = inputA.clone();
		
		for(int i=0 ; i<inputA.length;i++){//Adding O(n) complexity 
			if(!outputBReverse.contains(new Integer(inputA[i]))){//check for duplicate    -Adding  O(log n) complexity
				outputBReverse.addFirst(new Integer(inputA[i]));//add non duplicate value - Adding O(1) complexity (adding first to avoid complexity)
			}
			
			if(i!= 0 &&(inputA[i-1] == inputA[i])){//implies index i is duplicate 
				outputC[i] = 0;
			}
		}//job done
		
		outputB= new int[outputBReverse.size()];
		int ind = 0;
		for(int x = outputBReverse.size() - 1; x>= 0; x--){
			outputB[ind++] = outputBReverse.get(x);//reversing the reversed list to get the correct order
		}
		
		/*****Printing the output*******/
	
		System.out.print("B: ");
		for(int x: outputB){
			System.out.print(x);
		}
		System.out.println();
		System.out.print("C: ");
		for(int x: outputC){
			System.out.print(x);
		}
		
	}

}
